# write by hashaki
# first edit on 2018/11/14
# last change on 2018/11/18
# broker for simulation

class SimulationBroker:
    def __init__(self,simulateEngine):
        self.initcaptal=None
        self.simulateEngine=simulateEngine
    
    def getAccount(self):
        '''获取账户信息'''
        self.simulateEngine.capital           # 总资产
        self.simulateEngine.cash            # 持有现金
        self.simulateEngine.marketMoney     # 市值
    
    def buy(self,symbol,orderType,price,volume,strategy_name):
        '''买进'''
        self.simulateEngine.sendOrder(symbol,orderType,price,volume,strategy_name)
    
    def sell(self,symbol,orderType,price,volume,strategy_name):
        '''卖出'''
        self.simulateEngine.sendOrder(symbol,orderType,price,volume,strategy_name)
    
    def cancelOrder(self,OrderID=None):
        '''取消单个订单'''
        self.simulateEngine.cancelOrder(OrderID)

    def short(self,symbol,orderType,price,volume,strategy_name):
        """卖开"""
        self.simulateEngine.sendOrder(symbol,orderType,price,volume,strategy_name)
    
    def cover(self,symbol,orderType,price,volume,strategy_name):
        '''平仓'''
        self.simulateEngine.sendOrder(symbol,orderType,price,volume,strategy_name)
    
    def getOrderHistory(self):
        self.simulateEngine.tradeDict
    
    def setCash(self,cash):
        '''设置初始现金'''
        if isinstance(cash,int):
            self.capital=cash
        else:
            raise ValueError("现金初始值必须为int整数值")

    def getCash(self):
        print('还剩现金：',self.capital)
        return self.capital

    def getValue(self):
        pass

    def getPosition(self):
        pass